* (c) M. Ciccarelli. Rats version 7.2.
*
** REPLICATE FIGURES 1-3 OF THE PAPER: GLOBAL INFLATION
*
*
OPEN DATA cpi_DATA.xls    ;* SA data
CALENDAR 1960 1 4
ALL 2008:02
DATA(FORMAT=XLS,ORG=COLUMNS) 1960:01 2008:02
close data
comp seas = 1

source(noecho) bkfilter.src

if seas ==1
{
X11(GRADUATE) CPIQU2 / CPIQU2
X11(GRADUATE) CPIQAT / CPIQAT
X11(GRADUATE) CPIQLU / CPIQLU
X11(GRADUATE) CPIQIT / CPIQIT
X11(GRADUATE) CPIQPT / CPIQPT
X11(GRADUATE) CPIQNL / CPIQNL
X11(GRADUATE) CPIQSE / CPIQSE
X11(GRADUATE) CPIQBE / CPIQBE
X11(GRADUATE) CPIQDE / CPIQDE
X11(GRADUATE) CPIQDK / CPIQDK
X11(GRADUATE) CPIQES / CPIQES
X11(GRADUATE) CPIQFI / CPIQFI
X11(GRADUATE) CPIQuk / CPIQUK
X11(GRADUATE) CPIQFR / CPIQFR
X11(GRADUATE) CPIQGR / CPIQGR
X11(GRADUATE) CPIQIE / CPIQIE
X11(GRADUATE) CPIQUS / CPIQUS
X11(GRADUATE) CPIQJP / CPIQJP
X11(GRADUATE) CPIQAU / CPIQAU
X11(GRADUATE) CPIQCA / CPIQCA
X11(GRADUATE) CPIQNZ / CPIQNZ
X11(GRADUATE) CPIQNO / CPIQNO
X11(GRADUATE) CPIQCH / CPIQCH
X11(GRADUATE) CPIOECD / CPIOECD
}
end if

comp n = 24

dec vec[series] projections(n)
dec vec[series] infla(n)
dec vec[series] infla1(n)
dec vec[series] infla11(n)
dec vec[series] infla_BK(n)
*
do i = 1,n
set infla11(i) = 400.*log(([series] i)/(([series] i){1}))
set infla(i) = 100.*log(([series] i)/(([series] i){4}))
end

set average = 0.0
set average1 = 0.0

do i = 1,n
set average1 = average1+(1./n)*infla(i)
end

  comp count = 1
   dofor jj = infla(1) infla(2) infla(3) infla(4) infla(5) infla(6) infla(7) infla(8) $
    infla(9) infla(10) infla(11) infla(12) infla(13) infla(14) infla(15) infla(16)$
    infla(17) infla(18) infla(19) infla(20) infla(21) infla(22) infla(23)
    stat(noprint) jj
    set infla1(count) = (([series] jj)-%mean)/sqrt(%variance)
    comp count = count+1
   end


  @PRINCOMP(Ncomp=1) / pcomp
  # infla1(1) infla1(2) infla1(3) infla1(4) infla1(5) infla1(6) infla1(7) infla1(8) $
    infla1(9) infla1(10) infla1(11) infla1(12) infla1(13) infla1(14) infla1(15) infla1(16)$
    infla1(17) infla1(18) infla1(19) infla1(20) infla1(21) infla1(22) infla1(23)

   set factor = -pcomp(1)

stat(noprint) average1
set average = (average1-%mean)/sqrt(%variance)

stat(noprint) factor
set factor1 = (factor-%mean)/sqrt(%variance)

stat(noprint) infla(24)
set infla_oecd1 = (infla(24)-%mean)/sqrt(%variance)

set static_factor = factor1
set OECD = infla_oecd1


** FIGURE 1
graph(key=below) 3
# average
# static_factor
# oecd


do i = 1,n
  linreg(noprint) INFLA11(i)
  # constant average1
  prj projectioNS(I)
end


** FIGURE 2
SPGRAPH(HFIELDS=2,vfield=2)
graph(header='US') 2
# INFLA11(2)
# PROJECTIONS(2)
graph(header='Japan') 2
# INFLA11(5)
# PROJECTIONS(5)
graph(header='Canada') 2
# INFLA11(3)
# PROJECTIONS(3)
graph(header='UK') 2
# INFLA11(4)
# PROJECTIONS(4)
spgraph(done)

SPGRAPH(HFIELDS=2,vfield=2)
graph(header='Germany') 2
# INFLA11(6)
# PROJECTIONS(6)
graph(header='France') 2
# INFLA11(7)
# PROJECTIONS(7)
graph(header='Italy') 2
# INFLA11(8)
# PROJECTIONS(8)
graph(header='Euro area') 2
# INFLA11(1)
# PROJECTIONS(1)
spgraph(done)


  comp count = 1
   dofor jj = infla(1) infla(2) infla(3) infla(4) infla(5) infla(6) infla(7) infla(8) $
    infla(9) infla(10) infla(11) infla(12) infla(13) infla(14) infla(15) infla(16)$
    infla(17) infla(18) infla(19) infla(20) infla(21) infla(22) infla(23) infla(24)
    @BKFILTER(upper=6,ar=4) ([series] jj) * * infla_BK(count)
    comp count = count+1
   end

 set oecd1_bk = infla_bk(24)

   @PRINCOMP(Ncomp=1) / pcomp_bk
   # infla_bk(1) infla_bk(2) infla_bk(3) infla_bk(4) infla_bk(5) infla_bk(6) infla_bk(7) infla_bk(8) $
    infla_bk(9) infla_bk(10) infla_bk(11) infla_bk(12) infla_bk(13) infla_bk(14) infla_bk(15) infla_bk(16)$
    infla_bk(17) infla_bk(18) infla_bk(19) infla_bk(20) infla_bk(21) infla_bk(22) infla_bk(23)

   set factor1_bk = -pcomp_bk(1)

stat(noprint) factor1_bk
set factor_bk = (factor1_bk-%mean)/sqrt(%variance)
set average_bk = 0.0
DO I = 1,N
SET AVERAGE_BK = AVERAGE_BK+(1./N)*INFLA_bk(I)
END

stat(noprint) oecd1_bk
set oecd_bk = (oecd1_bk-%mean)/sqrt(%variance)

** FIGURE 3
graph(key=below) 3
# average_bk
# factor_bk
# oecd_bk

/*
open copy datafig12&3_2ndrevision.xls
copy(for=xls,org=obs,dates) / average static_factor oecd INFLA11(2) PROJECTIONS(2) INFLA11(5) PROJECTIONS(5) INFLA11(3) PROJECTIONS(3) $
INFLA11(4) PROJECTIONS(4) INFLA11(6) PROJECTIONS(6) INFLA11(7) PROJECTIONS(7) INFLA11(8) PROJECTIONS(8) INFLA11(1) PROJECTIONS(1) $
average_bk factor_bk oecd_bk
close copy
*/








